//
//  MyInfoView.m
//  wangzhe
//
//  Created by 李 佳伟 on 2017/10/18.
//  Copyright © 2017年 李 佳伟. All rights reserved.
//

#import "MyInfoView.h"

#import "JTCSM.h"


@implementation MyInfoView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (id)initWithFrame:(CGRect)frame imagename:(NSString *)imagename title:(NSString *)title placeholder:(NSString *)placeholder isShowLabel:(MyinfoviewType)isShow radioBtnIndex:(NSInteger)index GroupId:(NSString *)GroupId{
    self = [super initWithFrame:frame];
    if (self) {
        CGFloat space = 20;
        CGFloat imagesize = 15;
        CGFloat headerImagesize = 20;
        CGFloat height = frame.size.height;
        CGFloat width = frame.size.width;
        
        _imageView = [[UIImageView alloc]initWithFrame:(imagename == nil)?CGRectZero:CGRectMake(space, (height-headerImagesize)/2, headerImagesize, headerImagesize)];
        _imageView.image = [UIImage imageNamed:imagename];
        [self addSubview:_imageView];
        _imageView.userInteractionEnabled = YES;
        
        _label = [UILabel initWithFrame:CGRectMake(KVIEW_X(_imageView)+space , 0, 200, height) text:title font:15 textAlignment:NSTextAlignmentLeft texcolor:RGBACOLOR(51, 51, 51, 1) backgroundColor:nil];
        [self addSubview:_label];
        _label.userInteractionEnabled = YES;
        
        if (isShow == RightlabelType) {
            self.textfield = [UITextField initWithframe:CGRectMake(120 , 0, 200, height) backgrandColor:nil placeholder:placeholder textAlignment:NSTextAlignmentLeft font:14 texcolor:RGBACOLOR(89, 89, 89, 1)];
            [self addSubview:self.textfield];
            self.footerLabel.userInteractionEnabled = YES;
        }else if (isShow == labelType) {
            self.footerLabel = [UILabel initWithFrame:CGRectMake(width-space-200 , 0, 200, height) text:@"" font:14 textAlignment:NSTextAlignmentRight texcolor:[UIColor blackColor] backgroundColor:nil];
            [self addSubview:self.footerLabel];
            self.footerLabel.userInteractionEnabled = YES;
        }else if (isShow == ImageViewType){
            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(width-space-imagesize, (height-imagesize)/2, imagesize, imagesize)];
            imageView.image = [UIImage imageNamed:@"myFanhui.png"];
            [self addSubview:imageView];
            imageView.userInteractionEnabled = YES;
        } else if (isShow == RadioButton){
            
            //初始化单选按钮控件
            self.btn = [[ZYRadioButton alloc] initWithGroupId:GroupId index:index];
            //设置Frame
            self.btn.frame = CGRectMake(width-space-imagesize, (height-imagesize)/2, imagesize, imagesize);
            //添加到视图容器
            [self addSubview:self.btn];

        }else if (isShow == textfieldtype){
            
            self.textfield = [UITextField initWithframe:CGRectMake(width-space-200 , 0, 200, height) backgrandColor:nil placeholder:placeholder textAlignment:NSTextAlignmentRight font:14 texcolor:RGBACOLOR(89, 89, 89, 1)];
            [self addSubview:self.textfield];
            
            
        }else if (isShow == ImageandlabelViewType){
            
            self.footerLabel = [UILabel initWithFrame:CGRectMake(width-space-10-200-imagesize , 0, 200, height) text:@"" font:14 textAlignment:NSTextAlignmentRight texcolor:RGBACOLOR(51, 51, 51, 1) backgroundColor:nil];
            [self addSubview:self.footerLabel];
            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(width-space-imagesize, (height-imagesize)/2, imagesize, imagesize)];
            imageView.image = [UIImage imageNamed:@"myFanhui.png"];
            [self addSubview:imageView];
            imageView.userInteractionEnabled = YES;
            CGFloat dianviewsize = 5;
            _dianview = [[UIView alloc]initWithFrame:CGRectMake(width-space-10-imagesize, 10, dianviewsize, dianviewsize)];
            _dianview.backgroundColor = [UIColor redColor];
            [df layerWithView:_dianview radius:dianviewsize/2 width:0 color:nil];
            [self addSubview:_dianview];
            _dianview.hidden = YES;
        }else if (isShow == NoneType ){
            _label.frame = CGRectMake(KVIEW_X(_imageView)+space , 0, KSCREENWidth/2, height);
        }
        
        [self setUserInteractionEnabled:YES];
        [self setBackgroundColor:[UIColor whiteColor]];
       self.lineView =[df newlineViewWithHeightofTop:height superView:self spacing:space color:RGBACOLOR(241, 241, 241, 1) lineHeight:1];
        
    }
    
    return self;
}
- (void)showdianview:(BOOL)isshowdian{
    _dianview.hidden = !isshowdian;
}

@end
